﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Filesystem.Ntfs;
using System.IO;
using System.Threading;

namespace NTFS_Test
{
    class Program
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            //Mutex m = new Mutex(true,"a");
            
            Console.WriteLine("Input key word:");
            string key = "";
            key = Console.ReadLine();
            DriveInfo drive = new DriveInfo("d");
            
            NtfsReader ntfsReader =
               new NtfsReader(drive, RetrieveMode.All); //耗时严重
            
            IEnumerable<INode> nodes = ntfsReader.GetNodes(drive.Name); //耗时较多
            Console.WriteLine("Search Start!");
            int directoryCount = 0, fileCount = 0;
            foreach (INode node in nodes)
            {
                if ((node.Attributes & Attributes.Directory) != 0)
                    directoryCount++;
                else
                    fileCount++;
                if (node.Name.Contains(key))
                {
                    Console.WriteLine(node.FullName);
                }
            }

            Console.WriteLine(
                string.Format(
                    "Directory Count: {0}, File Count {1}",
                    directoryCount,
                    fileCount
                )
            );
            Console.ReadLine();
        }
    }
}
